﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FileGenerator
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }
        string filename;
        int mB, kB, B;
        bool bmB, bkB, bB, bSV;
        
        private void zakończToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void wybierzToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog savefile = new SaveFileDialog();
            savefile.ShowDialog();
            if (savefile.FileName != "")
            {
                filename = savefile.FileName;
                bSV = true;
            }
            savefile.Dispose();
        }

        private void btGenerate_Click(object sender, EventArgs e)
        {
            tbMB.Text.Trim();
            tbKB.Text.Trim();
            tbB.Text.Trim();

            if (tbMB.Text == "")
                tbMB.Text = "0";
            if (tbKB.Text == "")
                tbKB.Text = "0";
            if (tbB.Text == "")
                tbB.Text = "0";

            try
            {
                mB = Convert.ToInt32(tbMB.Text);
                bmB = true;
                tbMB.BackColor = Color.White;
            }
            catch (ArgumentNullException ex)
            {
                tbMB.Text = "0";
                mB = 0;
                bmB = true;
            }
            catch (Exception ex)
            {
                tbMB.BackColor = Color.Red;
                bmB = false;
            }

            try
            {
                kB = Int32.Parse(tbKB.Text);
                bkB = true;
                tbKB.BackColor = Color.White;
            }
            catch (ArgumentNullException ex)
            {
                tbKB.Text = "0";
                kB = 0;
                bkB = true;
            }
            catch (Exception ex)
            {
                tbKB.BackColor = Color.Red;
                bkB = false;
            }

            try
            {
                B = Int32.Parse(tbB.Text);
                bB = true;
                tbB.BackColor = Color.White;
            }
            catch (ArgumentNullException ex)
            {
                tbB.Text = "0";
                B = 0;
                bB = true;
            }
            catch (Exception ex)
            {
                tbB.BackColor = Color.Red;
                bB = false;
            }


            if (bmB && bkB && bB && bSV)
                CreateFile(filename,mB,kB,B);
        }

        private void CreateFile(string FileName, int mb, int kb, int b)
        {
            System.IO.StreamWriter file = new System.IO.StreamWriter(FileName);
            for (int i = 0; i < mb; i++)
                for (int ii = 0; ii <= 1023; ii++)
                    for (int iii = 0; iii <= 1023; iii++)
                    {
                        file.Write("a");
                    }

            for (int ii = 0; ii <= kb; ii++)
                for (int iii = 0; iii <= 1023; iii++)
                {
                    file.Write("b");
                }

            for (int iii = 0; iii <= b; iii++)
            {
                file.Write("b");
            }
            file.Close();
        }
    }
}
